import axios from 'axios';
import { requestBegin, requestEnd } from './actionCommon';
import { goodsUrl } from '../config/httpConfig';
// export const GET_GOODS = 'GET_GOODS';
export const GOODS_RECEIVED = 'GOODS_RECEIVED';
export const GOODS_INIT = 'GOODS_INIT';
axios.defaults.withCredentials = true;
export function getGoods (option) {
    return (dispatch) => {
        dispatch(requestBegin('isFetching'));
        return axios.get(goodsUrl, {
            params: option.query,
        })
            .then((res) => {
                dispatch(goodsReceived({
                    list: res.data,
                }));
                dispatch(requestEnd('success'));
            })
            .catch(err => {
                if (err) {
                    dispatch(requestEnd('err'));
                }
            });
    };
}
export function goodsReceived (data) {
    return {
        type: GOODS_RECEIVED,
        goods: data.list,
    };
}
export function goodsInit (data) {
    return {
        type: GOODS_INIT,
        goods: data,
    };
}
